import "thinkjs3-ts";
import path from "path";
import nunjucks from "think-view-nunjucks";
import fileSession from "think-session-file";
import { Console, File, DateFile } from "think-logger3";
import fileCache from "think-cache-file";
const isDev = think.env === "development";
import database from "./database";
console.log(database);

export const cache = {
  type: "file",
  common: {
    timeout: 24 * 60 * 60 * 1000, // millisecond
  },
  file: {
    handle: fileCache,
    cachePath: path.join(think.ROOT_PATH, "runtime/cache"), // absoulte path is necessarily required
    pathDepth: 1,
    gcInterval: 24 * 60 * 60 * 1000, // gc interval
  },
};

export const session = {
  type: "file",
  common: {
    cookie: {
      name: "thinkjs",
      // keys: ['werwer', 'werwer'],
      // signed: true
    },
  },
  file: {
    handle: fileSession,
    sessionPath: path.join(think.ROOT_PATH, "runtime/session"),
  },
};

export const view = {
  type: "nunjucks",
  common: {
    viewPath: path.join(think.ROOT_PATH, "view"),
    sep: "_",
    extname: ".html",
  },
  nunjucks: {
    handle: nunjucks,
  },
};

/**
 * model adapter config
 * @type {Object}
 */
export const model = {
  type: "mysql",
  common: {
    logConnect: isDev,
    logSql: isDev,
    logger: (msg: any) => think.logger.info(msg),
  },
  mysql: database,
};


/**
 * logger adapter config
 * @type {Object}
 */
export const logger = {
  type: isDev ? "console" : "dateFile",
  console: {
    handle: Console,
  },
  file: {
    handle: File,
    backups: 10, // max chunk number
    absolute: true,
    maxLogSize: 50 * 1024, // 50M
    filename: path.join(think.ROOT_PATH, "logs/app.log"),
  },
  dateFile: {
    handle: DateFile,
    level: "ALL",
    absolute: true,
    pattern: "-yyyy-MM-dd",
    alwaysIncludePattern: true,
    filename: path.join(think.ROOT_PATH, "logs/app.log"),
  },
};
